package co.fitstart.entity.course.round;

import java.beans.Transient;
import java.math.BigDecimal;
import java.util.HashMap;
import java.util.Map;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.ManyToOne;
import javax.persistence.Table;

import com.fasterxml.jackson.annotation.JsonIgnoreProperties;

@Entity
@Table(name = "course_round_group")
@JsonIgnoreProperties(value={"hibernate_lazy_initializer","handler","fieldHandler"})
public class CourseRoundGroup {
    
    @Id
    @GeneratedValue
    private Long id;
    
    /** 名称 */
    private String name;
    
    /** courseRound code */
    private String courseRoundCode;
    
    @ManyToOne(fetch = FetchType.LAZY, optional = false)
    private CourseRound courseRound;
    
    @Column(name = "is_disabled")
    private boolean disabled;
    
    /**
     * The default constructor
     */
    public CourseRoundGroup() {
        
    }
    
    /**
     * 
     * @param name
     * @param courseRoundCode
     * @param courseRound
     */
    public CourseRoundGroup(String name, String courseRoundCode, CourseRound courseRound) {
        this.name = name;
        this.courseRoundCode = courseRoundCode;
        this.courseRound = courseRound;
    }
    
    /**
     * 
     * @param name
     * @return
     */
    public CourseRoundGroup editName(String name) {
        this.name = name;
        return this;
    }
    
    /**
     * 
     * @return
     */
    public CourseRoundGroup disable() {
        this.disabled = true;
        return this;
    }
    
    /**
     * 
     * @return
     */
    @Transient
    public Map<String, BigDecimal> getInterval() {
        String[] names = this.name.split("-");
        Map<String, BigDecimal> interval = new HashMap<String, BigDecimal>();
        interval.put("min", new BigDecimal(names[0]));
        interval.put("max", new BigDecimal(names[1]));
        return interval;
    }

    /**
     * @return the id
     */
    public Long getId() {
        return id;
    }

    /**
     * @return the name
     */
    public String getName() {
        return name;
    }

    /**
     * @return the courseRoundCode
     */
    public String getCourseRoundCode() {
        return courseRoundCode;
    }

    /**
     * @return the courseRound
     */
    public CourseRound getCourseRound() {
        return courseRound;
    }

    /**
     * @return the disabled
     */
    public boolean isDisabled() {
        return disabled;
    }

    /**
     * @param id the id to set
     */
    public void setId(Long id) {
        this.id = id;
    }

    /**
     * @param name the name to set
     */
    public void setName(String name) {
        this.name = name;
    }

    /**
     * @param courseRoundCode the courseRoundCode to set
     */
    public void setCourseRoundCode(String courseRoundCode) {
        this.courseRoundCode = courseRoundCode;
    }

    /**
     * @param courseRound the courseRound to set
     */
    public void setCourseRound(CourseRound courseRound) {
        this.courseRound = courseRound;
    }

    /**
     * @param disabled the disabled to set
     */
    public void setDisabled(boolean disabled) {
        this.disabled = disabled;
    }
    
    

}
